<template>
  <div class="warning">
    <el-row>
      <el-table :data="noticeData" style="width: 100%" border>
        <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort"></el-table-column>
        <el-table-column prop="providerName" label="供应商名称" align="center"></el-table-column>
        <el-table-column prop="contact" label="联系人" align="center">
        </el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="phone" label="座机号码" align="center"></el-table-column>
        <el-table-column prop="cellPhone" label="手机号码" align="center"></el-table-column>
        <el-table-column prop="createDate" label="下单时间" align="center"></el-table-column>
        <el-table-column prop="" label="操作" align="center" width="200">
          <template slot-scope="scope">
            <span
              class="el-tag el-tag--warning el-tag--small"
              style="cursor: pointer;"
              @click="orderDetail(scope.row)"
              size="mini"
            >详情</span>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="text-align: right;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 50, 100, 200]"
        :page-size="pageSize"
        layout="->, sizes, prev, pager, next, jumper, total"
        :total="totalElements"
      ></el-pagination>
    </el-row>
    <orderDetail :rowData="rowdata" :off.sync="orderDialog"></orderDetail>
  </div>
</template>

<script>
import { getOrderList,delWarehouse } from "@/api/jxc/purchase.js";
import * as util from "@/util/util.js";
export default {
  name: "warning",
  components: {
      "orderDetail": () => import("./orderDetail")
  },
  data() {
    return {
      goodsNumber: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      selectDate: "",
      noticeData: [],
      pageSize: 15,
      currentPage: 1,
      totalElements: 0,
      totalPages: 1,
      orderDialog: false,
      rowdata: {},
      title: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    orderDetail(row){
     console.log(row);
      this.rowdata = row;
      this.orderDialog = true;
    },
    add() {
      this.title = "新增仓库";
      this.supplierDialog = true;
    },
    del(row) {
      console.log("row", row);
      delWarehouse({ storehouseId: row.storehouseId }).then(
        res => {
          this.$notify.success("删除成功");
          this.getList();
        },
        err => {}
      );
    },
    getList() {
      getOrderList({
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then(
        res => {
          console.log("res采购订单接口", res);
          this.noticeData = res.data.list;
          this.noticeData.forEach(e => {
            e.createDate = util.timestampToTime(e.createDate);
            if (e.notificationType == 1) {
              e.notificationType = "店铺平台通知";
            } else {
              e.notificationType = "区域平台通知";
            }
          });
          this.totalElements = res.data.total;
        },
        err => {}
      );
    },
    //序号
    indexSort(index) {
      if (this.currentPage > 1) {
        index = (this.currentPage - 1) * this.pageSize + index + 1;
      } else {
        index = index + 1;
      }
      return index;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style lang="less" props>
.pushList {
}
</style>